#include "Define/LevelLineComponentCollection.h"

#include "EditorDirectories.h"
#include "Component/LineReplicationGraphComponent.h"

void FLevelLineComponentCollection::AddActor(ULineReplicationGraphComponent* Component)
{
	if(!Component)
	{
		return;
	}
	const FName& StreamingLevelName = Component->GetNewReplicatedActorInfo().StreamingLevelName;
	if(StreamingLevelName.IsNone())
	{
		return;
	}
	FLineComponentContainer* Array = LevelComponentMap.Find(StreamingLevelName);
	if(!Array)
	{
		Array = &LevelComponentMap.Add(StreamingLevelName);
	}
	Array->Add(Component);
}

bool FLevelLineComponentCollection::RemoveActor(ULineReplicationGraphComponent* Component)
{
	if(!Component)
	{
		return false;
	}
	const FName& StreamingLevelName = Component->GetNewReplicatedActorInfo().StreamingLevelName;
	if(StreamingLevelName.IsNone())
	{
		return false;
	}
	if(FLineComponentContainer* Array = LevelComponentMap.Find(StreamingLevelName))
	{
		return Array->Remove(Component);
	}
	return false;
}

void FLevelLineComponentCollection::Reset()
{
	for(auto& KeyValue : LevelComponentMap)
	{
		KeyValue.Value.Reset();
	}
}
